<template>
  <div>
    <header-text :seller="seller"></header-text>
  </div>
</template>

<script>
import { getSeller } from 'api/index'
import headerText from './components/headerText'
import headerDetail from './components/headerDetail'
import { mapMutations } from 'vuex'

// 获取请求的参数
// import urlParse from 'assets/js/util.js'
import qs from 'query-string'

//处理url的获取问题
let url = (location.search || location.hash).match(/(\?.+)/) ? RegExp.$1 : ''


export default {
  name: 'v-header',
  data() {
    return {
      seller: {
        // id: urlParse(),
        id: qs.parse(url).id || 2,
      },
    }
  },
  created() {
    this._getSeller()
  },
  methods: {
    _getSeller() {
      getSeller({}).then((data) => {
        this.seller = Object.assign({}, this.seller, data.seller)

        // 蒋seller存到Vuex
        this.changeSeller(this.seller)
      })
    },
    ...mapMutations(['changeSeller']),
  },
  components: {
    headerText,
    headerDetail,
  },
}
</script>
